home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Taifun / Taifun 099 (1989-05-15)(Ossowski, Stefan)(DE)(PD).zip / Taifun 099 (1989-05-15)(Ossowski, Stefan)(DE)(PD).adf / PCQ / Examples / Copier.p < prev    next >
Text File  |  1989-03-31  |  2KB  |  75 lines

  1. Program Copy;
  2.  
  3. {$I "Include/DOS.i"}
  4.  
  5. var
  6.     InputFileName  : String;
  7.     OutputFileName : String;
  8.     Infile         : FileHandle;
  9.     Outfile        : FileHandle;
  10.     Position       : Integer;
  11.     Buffer       : ^array [1..1000] of char;
  12.  
  13. Function GetFileName(var index : Integer): String;
  14.  
  15. {
  16.     This function requires that each file name in the command
  17.     line have at least one character of disposable delimeter
  18.     after it.  It starts looking from index, and returns a
  19.     pointer into the command line.  Index ends up as the next
  20.     unused character.
  21. }
  22.  
  23. var
  24.    name : String;
  25. begin
  26.     while ((CommandLine[index] = ' ') or (CommandLine[index] = chr(9))) and
  27.     (index < 128) do
  28.     index := index + 1;
  29.     if index >= 128 then begin
  30.     writeln('Bad file name.');
  31.     exit(20);
  32.     end;
  33.     name := String(adr(CommandLine[index]));
  34.     while (ord(CommandLine[index]) > ord(' ')) and
  35.       (ord(CommandLine[index]) < 128) and
  36.     (index < 128) do
  37.     index := index + 1;
  38.     if index >= 128 then begin
  39.     writeln('Bad file name.');
  40.     exit(20);
  41.     end;
  42.     CommandLine[index] := chr(0);
  43.     index := index + 1;
  44.     GetFileName := name;
  45. end;
  46.  
  47. begin
  48.     Position := 1;
  49.     InputFileName := GetFileName(Position);
  50.     OutputFileName := GetFileName(Position);
  51.  
  52.     Infile := DOSOpen(InputFileName, ModeOldFile);
  53.     if Infile <> nil then begin
  54.     Outfile := DOSOpen(OutputFileName, ModeNewFile);
  55.     if Outfile <> nil then begin
  56.         New(Buffer);
  57.         repeat
  58.         Position := DOSRead(Infile, Buffer, 1000);
  59.         if Position > 0 then begin
  60.             Position := DOSWrite(Outfile, Buffer, Position);
  61.             if Position = 0 then begin
  62.             writeln('Write error');
  63.             exit(20);
  64.             end;
  65.         end;
  66.         until Position = 0;
  67.         Dispose(Buffer);
  68.         DOSClose(Outfile);
  69.     end else
  70.         writeln('Could not open output file.');
  71.     DOSClose(Infile);
  72.     end else
  73.     writeln('Could not open input file.');
  74. end.
  75.